Definition:
- This smell occurs when a test method contains unexplained and undocumented numeric literals as parameters or as values to identifiers. These magic values do not sufficiently indicate the meaning/purpose of the number. Hence, they hinder code understandability. Consequently, they should be replaced with constants or variables, thereby providing a descriptive name for the value.
Code Example:
@Test
public void testGetLocalTimeAsCalendar() {
Calendar localTime = calc.getLocalTimeAsCalendar(BigDecimal.valueOf(15.5D), Calendar.getInstance());
assertEquals(15, localTime.get(Calendar.HOUR_OF_DAY));
assertEquals(30, localTime.get(Calendar.MINUTE));
}
References:
Quality attributes
- :octicon:`file-code;1em` - Code Example
- :octicon:`comment-discussion;1em` - Cause and Effect
- :octicon:`graph;1em` - Frequency
- :octicon:`sync;1em` - Refactoring
- A survey on test practitioners' awareness of test smells
- An Exploratory Study on the Refactoring of Unit Test Files in Android Applications :octicon:`comment-discussion;1em` :octicon:`sync;1em`
- Analyzing Test Smells Refactoring from a Developers Perspective :octicon:`comment-discussion;1em` :octicon:`graph;1em` :octicon:`sync;1em`
- Automatic Identification of High-Impact Bug Report by Product and Test Code Quality
- Automatic generation of smell-free unit tests :octicon:`comment-discussion;1em`
- Characterizing High-Quality Test Methods: A First Empirical Study :octicon:`graph;1em`
- Handling Test Smells in Python: Results from a Mixed-Method Study
- How are test smells treated in the wild? A tale of two empirical studies :octicon:`graph;1em`
- Investigating Severity Thresholds for Test Smells :octicon:`comment-discussion;1em`
- Investigating Test Smells in JavaScript Test Code :octicon:`graph;1em`
- On the Distribution of "Simple Stupid Bugs" in Unit Test Files: An Exploratory Study
- On the diffusion of test smells and their relationship with test code quality of Java projects :octicon:`graph;1em`
- On the distribution of test smells in open source Android applications: an exploratory study :octicon:`file-code;1em` :octicon:`graph;1em`
- On the influence of Test Smells on Test Coverage
- On the test smells detection: an empirical study on the jnose test accuracy :octicon:`graph;1em`
- On the use of test smells for prediction of flaky tests :octicon:`comment-discussion;1em` :octicon:`graph;1em`
- PyNose: A Test Smell Detector For Python :octicon:`comment-discussion;1em` :octicon:`graph;1em`
- Pytest-Smell: a smell detection tool for Python unit tests :octicon:`graph;1em`
- Refactoring Test Smells: A Perspective from Open-Source Developers :octicon:`file-code;1em` :octicon:`sync;1em`
- Software Unit Test Smells :octicon:`file-code;1em`
- Test Artifacts — The Practical Testing Book :octicon:`file-code;1em` :octicon:`sync;1em`
- Test Smell Detection Tools: A Systematic Mapping Study
- The secret life of test smells-an empirical study on test smell evolution and maintenance :octicon:`graph;1em`
- What the Smell? An Empirical Investigation on the Distribution and Severity of Test Smells in Open Source Android Applications :octicon:`file-code;1em` :octicon:`graph;1em`
- tsDetect: an open source test smells detection tool